package cn.bluethink.eguan.rewardtask.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import cn.bluethink.eguan.model.core.EgTask;
import cn.bluethink.eguan.model.rewardtask.EgRewardTask;

/**
 * 悬赏任务实体模型
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @note 修订历史： 1、wanglei于2018/10/18设计并构建初始版本v0.1.0
 */
@Table(name = "eg_rewardtask")
public class EgRewardTaskEntity implements Serializable {

    private static final long serialVersionUID = -6236004965563314100L;

    @Id
    private Long tid;

    // 账户ID
    private Long acount;

    // bt币
    private Integer btCoin;

    // 限制领取任务的人数.为0代表无限制,默认为1
    private Integer limitNum;

    // 接受者计数
    @Column(name = "receiver_count")
    private Integer rvCount;

    // 接受者累计赏金数
    @Column(name = "receiver_btcoin")
    private Integer rvBtCoin;

    private Date utime;

    // 个人或团队悬赏标识（true为个人，默认为团队）
    private Boolean bmine;

    public EgRewardTaskEntity() {

    }

    /**
     * 转为实体模型
     * 
     * @param rewardTask
     * @param acount
     *            账户ID
     */
    public EgRewardTaskEntity(EgRewardTask rewardTask, Long acount) {
        this.tid = rewardTask.getId();
        this.acount = acount == null ? null : acount;
        this.btCoin = rewardTask.getBtCoin() == null ? 0 : rewardTask.getBtCoin();
        this.limitNum = rewardTask.getLimit() == null ? 1 : rewardTask.getLimit();
        this.rvCount = rewardTask.getRvcount() == null ? 0 : rewardTask.getRvcount();
        this.rvBtCoin = rewardTask.getRvBtCoin() == null ? 0 : rewardTask.getRvBtCoin();
        this.bmine = rewardTask.getBmine() == null ? false : rewardTask.getBmine();
    }

    /**
     * 转换为悬赏任务模型(包含任务详情)
     * 
     * @param task
     *
     * @return
     */
    public EgRewardTask createEgRewardTask(EgTask task) {

        EgRewardTask rewardTask = new EgRewardTask(tid, null, null);
        BeanUtils.copyProperties(task, rewardTask);
        rewardTask.setBtCoin(btCoin);
        rewardTask.setLimit(limitNum);
        rewardTask.setRvcount(rvCount);
        rewardTask.setRvBtCoin(rvBtCoin);
        rewardTask.setBmine(bmine);
        return rewardTask;
    }

    /**
     * 转换为悬赏任务模型(只包含特有属性)
     * 
     * @return
     */
    public EgRewardTask createEgRewardTask() {

        EgRewardTask rewardTask = new EgRewardTask(tid, null, null);
        rewardTask.setBtCoin(btCoin);
        rewardTask.setLimit(limitNum);
        rewardTask.setRvcount(rvCount);
        rewardTask.setRvBtCoin(rvBtCoin);
        // 设置悬赏任务特有字段的更新的时间
        rewardTask.setUtime(utime);
        rewardTask.setBmine(bmine);
        return rewardTask;
    }

    public Long getTid() {
        return tid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public Long getAcount() {
        return acount;
    }

    public void setAcount(Long acount) {
        this.acount = acount;
    }

    public Integer getBtCoin() {
        return btCoin;
    }

    public void setBtCoin(Integer btCoin) {
        this.btCoin = btCoin;
    }

    public Integer getLimitNum() {
        return limitNum;
    }

    public void setLimitNum(Integer limitNum) {
        this.limitNum = limitNum;
    }

    public Integer getRvCount() {
        return rvCount;
    }

    public void setRvCount(Integer rvCount) {
        this.rvCount = rvCount;
    }

    public Integer getRvBtCoin() {
        return rvBtCoin;
    }

    public void setRvBtCoin(Integer rvBtCoin) {
        this.rvBtCoin = rvBtCoin;
    }

    public Date getUtime() {
        return utime;
    }

    public void setUtime(Date utime) {
        this.utime = utime;
    }

    public Boolean getBmine() {
        return bmine;
    }

    public void setBmine(Boolean bmine) {
        this.bmine = bmine;
    }
}
